﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BingImages
{
    public class Settings
    {
        private string _path;
        public string path
        {
            get { return _path; }
        }

        private string _start;
        public string start
        {
            get { return _start; }
        }

        private string _archivePicture;
        public string archivePicture
        {
            get { return _archivePicture; }
        }

        private string _archiveDelete;
        public string archiveDelete
        {
            get { return _archiveDelete; }
        }

        private string _numberPicture;
        public string numberPicture
        {
            get { return _numberPicture; }
        }

        private string _timeInterval;
        public string timeInterval
        {
            get { return _timeInterval; }
        }

        private string _wallpaperScroll;
        public string wallpaperScroll
        {
            get { return _wallpaperScroll; }
        }

        public Settings()
        {
            _path = ConfigurationManager.AppSettings["path"];
            _start = ConfigurationManager.AppSettings["start"];
            _archivePicture = ConfigurationManager.AppSettings["archiveImage"];
            _archiveDelete = ConfigurationManager.AppSettings["archiveDelete"];
            _numberPicture = ConfigurationManager.AppSettings["numberPicture"];
            _timeInterval = ConfigurationManager.AppSettings["timeInterval"];
            _wallpaperScroll = ConfigurationManager.AppSettings["wallpaperScroll"];
        }

        public void save(string key, string value)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.AppSettings.Settings.Remove(key);
            config.AppSettings.Settings.Add(key, value);
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }

        public bool pathExist()
        {
            bool exist = false;

            if (!string.IsNullOrEmpty(this._path) && Directory.Exists(this._path))
            {
                exist = true;
            }

            return exist;
        }
    }
}
